package com.bootdo.system.controller;

import com.bootdo.system.domain.ApptupianDO;
import com.bootdo.system.domain.BizhongDO;
import com.bootdo.system.domain.JiaoyiVO;
import com.bootdo.system.domain.LunbotuDO;
import com.bootdo.system.service.ApptupianService;
import com.bootdo.system.service.BizhongService;
import com.bootdo.system.service.JiaoyicelueService;
import com.bootdo.system.service.LunbotuService;
import com.bootdo.system.utils.R;
import com.huobi.HuobiInfoUtils;
import com.huobi.model.market.MarketTicker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@ResponseBody
@Controller
public class IndexController extends  BaseController{

    @Autowired
    private LunbotuService lunbotuService;
    @Autowired
    private BizhongService bizhongService;
    @Autowired
    private JiaoyicelueService jiaoyicelueService;
    @Autowired
    private ApptupianService apptupianService;

    @GetMapping(value = {"/","/index"})
    public R indexPage(Model model, HttpServletRequest request) {

        ApptupianDO indexleft = apptupianService.get(2);
        ApptupianDO indexright = apptupianService.get(3);
        //轮播
        List<LunbotuDO> lunbotuDOS = lunbotuService.list(new HashMap<>());
        //币种
        List<BizhongDO> bizhongDOS = bizhongService.qian3();
        //全部循环
        List<JiaoyiVO> jiaoyiVOS = jiaoyicelueService.listwithKeyword(getUserId(request),null);
        //打开的循环
        List<JiaoyiVO> openlist = new ArrayList<>();

        for (JiaoyiVO jiaoyi:jiaoyiVOS) {
            if(jiaoyi.getCeluestatus()==1){
                openlist.add(jiaoyi);
            }
        }


        return R.ok()
                .put("indexleft",indexleft)
                .put("indexright",indexright)
                .put("lunbotuDOS",lunbotuDOS)
                .put("bizhongDOS",bizhongDOS)
                .put("openlist",openlist);
    }


}
